<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>tabControl切换(tab control switch)</title>
  <link rel="stylesheet" href="./css/reset.css">
  <link rel="stylesheet" href="./css/common.css">
  <style>
    .main .section-content {
      display: flex;
      justify-content: space-between;
    }

    .main .section-content .left-content {
      width: 872px;
      height: 1000px;
    }

  </style>
</head>
<body>

  <div class="main main_wrapper">
    <div class="section-content">
      <div class="left-content">
        <div class="content-center">
          <div class="section_header">
            <div class="header_left">
              <h3 class="title">内容中心</h3>
            </div>
            <div class="header_right">
              <a href="#" class="more">更多</a>
            </div>
          </div>
          <div class="tab_control">
            <!-- <div class="item active">精品栏目</div>
            <div class="line"></div>
            <div class="item">赛事精品</div>
            <div class="line"></div>
            <div class="item">英雄攻略</div> -->
          </div>
        </div>
      </div>
    </div>
  </div>

  <script>
    const tabControlData = [
      {
        title: "精品栏目",
        line: true,
        active: true
      },
      {
        title: "赛事精品",
        line: true
      },
      {
        title: "英雄攻略",
      }
    ]

    const tabControl = document.querySelector(".tab_control")
    tabControlData.forEach(item => {
      const createItemEl = document.createElement("div")
      createItemEl.className = "item"
      createItemEl.textContent = item.title
      if (item.active) {
        createItemEl.classList.add("active")
      }

      if (item.line) {
        const createLineEl = document.createElement("div")
        createLineEl.className = "line"
        tabControl.append(createItemEl, createLineEl)
      } else {
        tabControl.append(createItemEl)
      }
    })

    let activeEl = document.querySelector(".active")
    tabControl.onmouseover = function (e) {
      const itemEl = e.target
      if (itemEl.className === "item") {
        activeEl.classList.remove("active")
        itemEl.classList.add("active")
        activeEl = itemEl
      } 
    }

  </script>
  
</body>
</html>